<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>双向绑定</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }
    </style>
</head>

<body>
    <!-- name改为"李白",data中添加name属性,值为"李白" -->
    <input type="text" placeholder="请输入姓名" value="" v-module="name">
    <input type="text" placeholder="请输入年龄" value="" v-module="age">
    <input type="text" placeholder="请输入年龄" value="">


    <script type="text/javascript">
        var data = {
            
        }

        // 获取页面上所有带v-module属性的输入框
        var ipts = document.querySelectorAll("input[v-module]");
        console.log(ipts);
        for(var i = 0; i < ipts.length; i ++){
            var key = ipts[i].getAttribute("v-module");
            (function (index){
                Object.defineProperties(data, {
                    [key]: {
                        get(){
                            console.log(index);
                            return ipts[index].value;
                        },
                        set(v){
                            ipts[index].value = v;
                        }
                    }
                })

                /* Object.defineProperty(data, key, {
                    get(){

                    }
                }) */
            })(i)
        }
    </script>
</body>

</html>